package main

import (
	"fmt"
)

//运算符

type date struct {
	x int
	s string
}

func main() {

	/*
		&  +=  &=  !=  >>=  ... .  :

		1.* / % >>  <<  &
		2.+  -  |  ^(异或)
		3.&&
		4.||
		5.;
	*/

	//二进制运算符
	const (
		read byte = 1 << iota
		write
		exec
		freeze
	)
	fmt.Println(read)
	fmt.Println(write)
	fmt.Println(exec)
	fmt.Println(freeze)
	a := read | write | freeze
	b := read | write | exec

	fmt.Println(a)
	fmt.Println(b)

	c := a &^ b
	fmt.Println(c)
	fmt.Printf("%04b &^ %04b = %04b\n", a, b, c)

	//在go语言里，自增和自减不是运算符，它是一个语句，不能作为if的表达式
	//d:=1
	//++d
	//fmt.Println(d)

	d := 1
	p := &d
	*p++
	fmt.Println(*p)

	x := 10
	var p1 *int = &x
	*p1 += 20
	fmt.Println(p1, *p1)

	//指针不能做运算,只能获取变量、地址等
	//p2 := &x
	//p2++
	//fmt.Println(p2)

	p2 := &x
	p2 = nil
	fmt.Println(p2)

	//结构体
	var a1 date = date{1, "abc"}
	fmt.Println(a1)

	b1 := date{
		1, "abc",
	}
	c1 := &date{
		1,
		"abc",
	}
	fmt.Println(b1, c1)

}
